import {defineStore} from 'pinia'
import util from "@utils/util";
import {getMenus, getMenuTree} from "@utils/element-helper";
import {commonStore} from "@/store/common";

export const menuStore = defineStore({
    id: 'menu',
    state: () => ({
        menus: [],
        menusArray: [],
        activeMenu: "/dashboard",
    }),
    getters: {},
    actions: {
        load() {
            let commonS = commonStore()
            commonS.loading = true
            this.loadMenus()
            this.loadMenusArray()
            commonS.loading = false
        },
        loadMenus() {
            getMenuTree().then(data => {
                this.menus = data
            }).catch(e => console.log(e))
        },
        loadMenusArray() {
            getMenus().then(data => {
                this.menusArray = util.treeToArray(data)
            }).catch(e => console.log(e))
        },

    }
})
